import React, {useState,useEffect} from 'react';
import { useHistory ,Link} from "react-router-dom";
import http from "../../model/http";
import {Button, Toast} from 'antd-mobile';
import Header from "../../components/header/Header";
import './bind.less'
import Input from "../../components/input/Input";
import number from "less/lib/less/functions/number";
import code from "../../model/code";
function Bind() {
    const history = useHistory();
    const [codeImg,setCodeImg] = useState({})
    const [codeValue,setCodeValue] = useState()
    const [username,setUsername] = useState()
    const [password,setPassword] = useState()

    // let url =window.location.href
    // console.log("url",url)
    // let gotoType = url.substring(url.lastIndexOf("/")+1);
    useEffect( async ()=>{
       
        
    },[])

    const changeUsername=(e)=> {
        setUsername(e.target.value)
    }
    const changePassword=(e)=> { 
        setPassword(e.target.value)
    }
    const onBind =async()=>{
        // http://wxwork.gzsg.cn/wxwork/arsmo/wxworkBindSub?hosId=1&account=sg03216&password=1&userId=LiHao&managerId=1000127

        const user =JSON.parse(window.localStorage.getItem('user'))
        const check =JSON.parse(window.localStorage.getItem('check'))

        const res = await http.outPost('/arsmo/wxworkBindSub', {
            account:username,
            password:password,
            userId: user.userid,
            // userId: 'SG03133', // 暂时写死
            hosId: window.localStorage.getItem("hosId") || window.hos.hosId,
            managerId : check.managerId
        })
        
        if(res.code==0){
            Toast.success(res.msg,1.5, async ()=>{
                history.go(-2)
            })
        }else{
            Toast.fail(res.msg,2)
        }






    }

    return (
    <div className='login'>
        <div className='form-wrapper'>
            <div className='title'> 曙光医疗管理系统</div>
            <div className='g-flex-col'>
                <input type="text" className='g-mt20' value={username} maxLength="20"  onChange={changeUsername.bind(this)}  placeholder='请输入账号'/>
                <input type="text" className='g-mt20' value={password} maxLength="20" onChange={changePassword}  placeholder='请输入密码'/>
                {/*<div className='g-flex g-mt20 '>*/}
                {/*    <input type="text" className='code-input' value={codeValue}  onChange={change.bind(this)} placeholder='输入验证码'/>*/}
                {/*    {*/}
                {/*        codeImg?.img&&( <img onClick={reLoadImg} className='code-img' src={'data:image/jpg;base64,'+codeImg.img} alt=""/>)*/}
                {/*    }*/}
                {/*</div>*/}
                <Button className='login-bt' type="primary"  onClick={onBind}>立即绑定</Button>
            </div>
            
        </div>
        <Header/>
    </div>
  )
}

export default Bind;

